#include<bits/stdc++.h>
using namespace std;
int T,n,a[200010],ans;
bool f[1000010];
inline int read()
{
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)&&c!='-') c=getchar();
    if(c=='-')
    {
        f=-1;
        c=getchar();
    }
    while(isdigit(c))
    {
        x=x*10+c-'0';
        c=getchar();
    }
    return x*f;
}
inline void write(long long x)
{
    if(x<0)
    {
        putchar('-');
        x=-x;
    }
    if(x>9) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    T=read();
    while(T--)
    {
		ans=0;
        n=read();
        for(int i=1;i<=n;i++)
        {
            a[i]=read();
            if(f[a[i]]) ans+=a[i];
            else f[a[i]]=1;
        }
        write(ans);
        putchar('\n');
        for(int i=1;i<=n;i++) f[i]=0;
    }
    return 0;
}
